<?php
/**
 * This file is part of Hyperf Mall.
 *
 * @link     https://gitee.com/scwlkj/hyperf_mall
 * @contact  hyperf_mall@163.com
 */

namespace App\JsonRpc;

use App\Repository\HotSearchRepository;
use Hyperf\RpcServer\Annotation\RpcService;
use App\JsonRpc\Interfaces\HotSearchServiceInterface;

/**
 * @RpcService(name="Config::HotSearchService", protocol="jsonrpc", server="jsonrpc")
 */
class HotSearchService extends BaseService implements HotSearchServiceInterface
{
    public function init()
    {
        $this->repository = HotSearchRepository::getInstance();
    }

    /**
     * Notes: A端列表
     * Author: Bruce.z
     * DateTime: 2022/8/16 16:37
     * @param array $condition
     * @param array $field
     * @param int $page
     * @param int $size
     * @return array
     */
    public function index(array $condition, array $field, int $page, int $size): array
    {
        if(isset($condition['name']) && !empty($condition['name'])){
            $condition[] = ['name', 'like', '%'.trim($condition['name']).'%'];
            unset($condition['name']);
        }
        return parent::index($condition, $field, $page, $size);
    }

    /**
     * Notes: c端 热搜词列表
     * Author: Bruce.z
     * DateTime: 2022/8/16 16:32
     * @return array
     */
    public function appList():array
    {
        return $this->repository->appList();
    }

    /**
     * Notes: c端 首页热搜词
     * Author: Bruce.z
     * DateTime: 2022/8/16 17:15
     * @return string
     */
    public function appOne():string
    {
        return $this->repository->appOne();
    }
}
